package webs;

import dao.pojo.Users;
import domain.ApplicationContext;
import domain.FileFacade;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: winstars
 * Date: 2007-2-28
 * Time: 18:39:24
 * To change this template use File | Settings | File Templates.
 */
public class FileUpload extends HttpServlet {
    /**
	 * 
	 */
	private static final long serialVersionUID = 5489485038184165344L;

	@Override
    protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
        httpServletRequest.setCharacterEncoding("UTF-8");
        Users user=(Users)httpServletRequest.getSession().getAttribute("login_user");
        if(user==null){
        	httpServletResponse.sendRedirect("ShowLogin");
        }else{
	        FileFacade fileService=(FileFacade)ApplicationContext.get("FileService");
	        
	        fileService.uploadFiles(httpServletRequest);
	        httpServletResponse.sendRedirect("ShowResources");
        }
    }

    public void destroy() {
        super.destroy();
    }

    public void init() throws ServletException {
        super.init();    
    }
}